package simulaco.web.jsf;

import gminet.infra.toolkit.ValidatorToolkit;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class EmailValidator implements Validator {

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

	String email = (String) value;
	if (!ValidatorToolkit.validateEmail(email)) {
	    FacesMessage message = new FacesMessage();
	    message.setSeverity(FacesMessage.SEVERITY_ERROR);
	    message.setSummary("Email inválido.");
	    throw new ValidatorException(message);
	}
    }

}
